<?php
$T->loadTpl("./html/".$template."/".$qname.".html");
$T->SetTpl('cssjs','html/cssjs.inc'); 
$T->SetTpl('jsmodel','html/jsmodel.inc');     
  
$id=isset($_GET["id"])?$_GET["id"]:"0";
$T->readDB("select A.*,B.truename as cname,C.name as typename from sys_plan A left join sys_member B on B.id=A.uid left join sys_plan_type C on C.id=A.type where A.id='".$id."'");
//附件
$attachment=$T->db->query("select attachment from sys_plan where id='".$id."'")->fetchColumn(0);
//if($attachment!=''){
    $attachment=explode(",", $attachment);
    foreach($attachment as $k=>$v){
        $attachment[$k]="'".$v."'";
    }
    $attachment=implode(",", $attachment);
    $T->SetBlock("attachment", "select * from sys_plan_attachment where id in({$attachment}) order by `timestamp`");
//}
$accept_html='';
//发布人员
$accepter = $T->db->query("select accepter from sys_plan where id='".$id."'")->fetchColumn(0);
$accepterarr = explode(',', $accepter); 
$aid='';
for($i=0;$i<count($accepterarr);$i++){
   $aid.="'".$accepterarr[$i]."',";
}
$condition = " and id in (".$aid."'')";
$list = $T->db->query("SELECT id,deptname FROM sys_department order by odx asc");
foreach ($list as $k => $val) {
    $accept_html .= '<tr>
                      <td>'.$val["deptname"].'</td>
                      <td>';
    $rp = $T->db->query("select id,truename from sys_member where department=".$val['id'].$condition." order by inserttime");
    foreach ($rp as $key => $value) {
        $accept_html.='<li>'.$value["truename"].'</li>';
    }
    $accept_html .= '</td></tr>';
}
//发布部门
$dept_id = $T->db->query("select dept_id from sys_plan where id='".$id."'")->fetchColumn(0);
$dept_idarr = explode(',', $dept_id);
foreach ($dept_idarr as $key => $deptid) {
   $dept_namearr[]=$T->db->query("select deptname from sys_department where id=".$deptid)->fetchColumn(0);
}
$dept_name=implode(',', $dept_namearr);
//负责人
$charge_uid = $T->db->query("select charge_uid from sys_plan where id='".$id."'")->fetchColumn(0);
$charge_uidarr = explode(',', $charge_uid);
foreach ($charge_uidarr as $key => $chargeid) {
   $charge_namearr[]=$T->db->query("select truename from sys_member where id='".$chargeid."'")->fetchColumn(0);
}
$charge_name=implode(',', $charge_namearr);
$T->Set("dept_name",$dept_name);
$T->Set("accept_html",$accept_html);
$T->Set("charge_name",$charge_name);

$T->Set("template",$template);       
$T->clearNaN();       
$T->clearNoN();
$T->display(); 